﻿
@{
    ViewData["Title"] = "HuiZongInfo";
}

<h1>财务管理</h1>
<input id="Button1" type="button" value="添加" onclick="Add()" />
<div id="box">

    <table class="table table-hover" style="text-align:center">
        <tr style="background-color: deepskyblue">
            <th>编号</th>
            <th>部门</th>
            <th>上月余额</th>
            <th>总收入</th>
            <th>总支出</th>
            <th>余额</th>
            <th>经手人</th>
            <th>日期</th>
            <th>操作</th>
        </tr>
        <tr v-for="(v) in msg">
            <td>{{v.hId}}</td>
            <td>{{v.deparMent }}</td>
            <td><span style="color:red">{{v.prvMounthPrice}}</span>元</td>
            <td>+<span style="color:red">{{v.income}}</span>元</td>
            <td>-<span style="color:red">{{v.expenditure}}</span>元</td>
            <td><span style="color:red">{{v.balance}}</span>元</td>
            <td>{{v.peopleHand }}</td>
            <td>{{v.startTime | formatTime('yyyy年MM月dd日') }}</td>
            <td>
                <input type="button" v-on:click="Del(v.hId)" value="删除" style="background-color: deepskyblue" />
            </td>
        </tr>
    </table>
</div>
<script>
    new Vue({
        el: '#box',
        data() {
            return {
                msg: [],
                id: 0,
            }
        },
        mounted: function () {
            axios
                .get("/Finance/GetZongInfos")
                .then(response => (this.msg = response.data))
                .catch(function (error) { // 请求失败处理
                    console.log(error);
                });
        },
        methods: {
            Del: function (hid) {
                this.id = hid;
                axios
                    .get("/Finance/DelHuiZong", {
                        params: {
                            id: this.id
                        }
                    })
                    .then(
                        function (i) {
                            if (i.data > 0) {
                                alert("删除成功！");
                                location.href = '/Finance/HuiZongInfo'
                            }
                            else {
                                alert("删除失败");
                            }
                        }
                    );

            }
        },
            filters: {
                formatTime: function (date, fmt) {
                    var date = new Date(date);
                    if (/(y+)/.test(fmt)) {
                        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                    }
                    var o = {
                        'M+': date.getMonth() + 1,
                        'd+': date.getDate(),
                        'h+': date.getHours(),
                        'm+': date.getMinutes(),
                        's+': date.getSeconds()
                    };
                    for (var k in o) {
                        if (new RegExp('(' + k + ')').test(fmt)) {
                            var str = o[k] + '';
                            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : ('00' + str).substr(str.length));
                        }
                    }
                    return fmt;
                },
                formatTime1: function (date, fmt) {
                    var date = new Date(date);
                    if (/(y+)/.test(fmt)) {
                        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                    }
                    var o = {
                        'M+': date.getMonth() + 1,
                        'd+': date.getDate(),
                        'h+': date.getHours(),
                        'm+': date.getMinutes(),
                        's+': date.getSeconds()
                    };
                    for (var k in o) {
                        if (new RegExp('(' + k + ')').test(fmt)) {
                            var str = o[k] + '';
                            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : ('00' + str).substr(str.length));
                        }
                    }
                    return fmt;
                }
            }
       
        })
    function Add() {
        location.href = '/Finance/AddHuiZong'
    }
    function Detial(hId) {
        location.href = '/Finance/XiangQin?id=' + hId;
    }

</script>